from core.uitest.page.LoginPage import LoginPage
from core.uitest import chrome_driver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class LoginServer(LoginPage):
    # def __init__(self):

    def open_login_url(self, url):
        chrome_driver.get(url)

    def enter_name(self, username, password):
        self.driver.find_element(*self.input_username).send_keys(username)
        self.driver.find_element(*self.input_password).send_keys(password)

    def click_sumit_button(self):
        self.driver.find_element(*self.login_button).click()

    def switch_iframe(self):
        iframe_switch = WebDriverWait(chrome_driver, 3).until(
            EC.presence_of_element_located(self.iframe)
        )
        # 切换到iframe
        chrome_driver.switch_to.frame(iframe_switch)

